use util::errors::{CargoError, CargoResult, CargoResultExt};
mod targets;
-use self::targets::{Layout, targets};
+use self::targets::targets;
pub fn read_manifest(path: &Path, source_id: &SourceId, config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
source_id: &SourceId,
config: &Config)
-> CargoResult<(EitherManifest, Vec<PathBuf>)> {
- let root = manifest_file.parent().unwrap();
- let layout = Layout::from_project_path(root);
+ let project_root = manifest_file.parent().unwrap();
let toml = {
let pretty_filename = util::without_prefix(manifest_file, config.cwd()).unwrap_or(manifest_file);
let manifest = Rc::new(manifest);
return match TomlManifest::to_real_manifest(&manifest,
source_id,
- &layout,
+ project_root,
config) {
Ok((mut manifest, paths)) => {
for key in unused {
Err(e) => {
match TomlManifest::to_virtual_manifest(&manifest,
source_id,
- &root,
+ project_root,
config) {
Ok((m, paths)) => Ok((EitherManifest::Virtual(m), paths)),
Err(..) => Err(e),
fn to_real_manifest(me: &Rc<TomlManifest>,
source_id: &SourceId,
- layout: &Layout,
+ project_root: &Path,
config: &Config)
-> CargoResult<(Manifest, Vec<PathBuf>)> {
let mut nested_paths = vec![];
// If we have no lib at all, use the inferred lib if available
// If we have a lib with a path, we're done
// If we have a lib with no path, use the inferred lib or_else package name
- let targets = targets(me, layout, project_name, &project.build)?;
+ let targets = targets(me, project_root, project_name, &project.build)?;
if targets.is_empty() {
debug!("manifest has no build targets");
}
- if let Err(e) = unique_build_targets(&targets, layout) {
+ if let Err(e) = unique_build_targets(&targets, project_root) {
warnings.push(format!("file found to be present in multiple \
build targets: {}", e));
}
config: config,
warnings: &mut warnings,
platform: None,
- root: &layout.root,
+ root: project_root,
};
fn process_dependencies(
/// Will check a list of build targets, and make sure the target names are unique within a vector.
/// If not, the name of the offending build target is returned.
-fn unique_build_targets(targets: &[Target], layout: &Layout) -> Result<(), String> {
+fn unique_build_targets(targets: &[Target], project_root: &Path) -> Result<(), String> {
let mut seen = HashSet::new();
- for v in targets.iter().map(|e| layout.root.join(e.src_path())) {
+ for v in targets.iter().map(|e| project_root.join(e.src_path())) {
if !seen.insert(v.clone()) {
return Err(v.display().to_string());
}
}
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
+pub
struct TomlTarget {
name: Option<String>,
/// Implicit Cargo targets, defined by conventions.
-pub struct Layout {
- pub root: PathBuf,
- pub lib: Option<PathBuf>,
- pub bins: Vec<PathBuf>,
- pub examples: Vec<PathBuf>,
- pub tests: Vec<PathBuf>,
- pub benches: Vec<PathBuf>,
+struct Layout {
+ root: PathBuf,
+ lib: Option<PathBuf>,
+ bins: Vec<PathBuf>,
+ examples: Vec<PathBuf>,
+ tests: Vec<PathBuf>,
+ benches: Vec<PathBuf>,
}
impl Layout {
/* else just don't add anything if the directory doesn't exist, etc. */
}
-pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_build: &Option<StringOrBool>) -> CargoResult<Vec<Target>> {
+pub fn targets(me: &TomlManifest, project_root: &Path, project_name: &str, custom_build: &Option<StringOrBool>) -> CargoResult<Vec<Target>> {
+ let layout = Layout::from_project_path(project_root);
let lib = match me.lib {
Some(ref lib) => {
lib.validate_library_name()?;
}
)
}
- None => inferred_lib_target(project_name, layout),
+ None => inferred_lib_target(project_name, &layout),
};
let bins = match me.bin {
};
bins.clone()
}
- None => inferred_bin_targets(project_name, layout)
+ None => inferred_bin_targets(project_name, &layout)
};
for bin in bins.iter() {
}
examples.clone()
}
- None => inferred_example_targets(layout)
+ None => inferred_example_targets(&layout)
};
let tests = match me.test {
}
tests.clone()
}
- None => inferred_test_targets(layout)
+ None => inferred_test_targets(&layout)
};
let benches = match me.bench {
}
benches.clone()
}
- None => inferred_bench_targets(layout)
+ None => inferred_bench_targets(&layout)
};
if let Err(e) = unique_names_in_targets(&bins) {